#include "ui_keyword.h"
#include "worddialog.hpp"

static char *codecs[] = {"UTF-8", "UTF-16", "KOI8-R", "CP1251", "CP866", "ISO-8859-5", NULL};

WordDialog::WordDialog(Keyword word)
{
	ui = new Ui_Keyword;
	ui->setupUi(this);
	ui->regexp->setText(word.regexp);
	QVBoxLayout *box = new QVBoxLayout(ui->box);
	ui->box->setLayout(box);

	char **codec = codecs;
	while(*codec){
		QCheckBox *check = new QCheckBox(ui->box);
		check->setText(*codec);
		check->setObjectName(*codec);
		box->addWidget(check);
		codec++;
	}

	QString str;
	foreach(str,word.cs){
		QCheckBox *check = ui->box->findChild<QCheckBox *>(str);
		check->setCheckState(Qt::Checked);
	}
}

WordDialog::~WordDialog()
{
	delete ui;
}

Keyword WordDialog::getKeyword() const
{
	Keyword word;
	word.regexp = ui->regexp->text();
	
	QCheckBox *check;
	QList<QCheckBox*> cs = ui->box->findChildren<QCheckBox*>();
	foreach(check, cs){
		if(check->checkState() == Qt::Checked)
			word.cs << check->objectName();
	}
	
	return word;
}
